package conversion;

import java.net.URL;
import java.util.List;

/**
 * Reprezentuje pojedyncza sesje.
 * @author Marcin
 *
 */
public class Session {
	private final int timeSeparator;
	private final User user;
	private final List<Request> sortedRequests; // zadania posortowane po czasie

	protected Session(User user, List<Request> requests, int timeSeparator) {
		this.user = user;
		this.sortedRequests = requests;
		this.timeSeparator = timeSeparator;
	}

	/**
	 * 
	 * @return Czas trwania sesji w sekundach.
	 */
	public int getDuration() {
		return (int) ((this.sortedRequests.get(this.sortedRequests.size() - 1).getTime().getTimeInMillis() - this.sortedRequests.get(
			0).getTime().getTimeInMillis()) / 1000);
	}

	/**
	 * @return the requests
	 */
	public List<Request> getRequests() {
		return sortedRequests;
	}

	public List<URL> getPages() {
		throw new UnsupportedOperationException();
	}

	/**
	 * Sredni czas na strone w sekundach.
	 * @return
	 */
	public double avaragePageTime() {
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		String result = this.user.getId() + "\n";
		for (Request r : this.sortedRequests)
			result += "    " + r.getResource() + "\n";
		return result;
	}

}
